package com.jiaotong.smart.smartjiaotong.mapper.GreenWaveMapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiaotong.smart.smartjiaotong.entity.GreenWave.GreenWaveCross;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 袁雨森
 * 绿波带中路口mapper
 */
@Repository
public interface GreenWaveCrossMapper extends BaseMapper<GreenWaveCross> {

    @Select("select id,cross_name,programme,phase_diff,coordination_phase,green_wave_id\n" +
            "from greenwavecross\n" +
            "where green_wave_id=#{id}")
    List<GreenWaveCross> getCrossListByGreenWaveId(@Param("id") Long id);

    @Insert("insert into greenwavecross\n" +
            "values (id, cross_name, programme, phase_diff, coordination_phase, green_wave_id)\n" +
            "on duplicate key update cross_name=#{crossName},programme=#{crossProgrammeId},phase_diff=#{phaseDiff},coordination_phase=#{coordinationPhase},green_wave_id=#{id}")
    void addGreenWaveCross(GreenWaveCross greenWaveCross, @Param("id") Long id);

    @Delete("delete from greenwavecross where id=#{crossId} and green_wave_id=#{greenWaveId}")
    int deleteGreenWaveCross(@Param("greenWaveId") Long greenWaveId, @Param("crossId") Long greenWaveCrossId);
}
